using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace JGSY.CourseManagement.Presentation.Navigation
{
    /// <summary>
    /// 定义导航服务的抽象接口，提供视图注册和区域导航功能
    /// </summary>
    public interface INavigationService
    {         /// <summary>
              /// 注册视图名称与类型映射
              /// </summary>
              /// <param name="viewName">视图名称</param>
              /// <param name="viewType">视图类型</param>
        void RegisterView(string viewName, Type viewType);

        /// <summary>
        /// 异步导航到指定视图
        /// </summary>
        /// <param name="viewName">已注册的视图名称</param>
        /// <param name="parameter">导航参数</param>
        /// <param name="cache">是否缓存视图</param>
        /// <returns>导航是否成功</returns>
        bool NavigateTo(string viewName, object parameter = null, bool cache = false);
        bool GoBack();
        bool CanGoBack { get; }
        void ClearHistory();
        Task NavigateToAsync(string v);

        event EventHandler<NavigationEventArgs> Navigated;
        event EventHandler<NavigationEventArgs> NavigationFailed;
    }

    public class NavigationEventArgs : EventArgs
    {
        public string ViewName { get; }
        public object Parameter { get; }
        public Exception Error { get; }

        public NavigationEventArgs(string viewName, object parameter)
        {
            ViewName = viewName;
            Parameter = parameter;
        }

        public NavigationEventArgs(string viewName, object parameter, Exception error)
            : this(viewName, parameter)
        {
            Error = error;
        }
    }
}